<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(nums) {
      let min = Math.min.apply(null, nums.map(i => i < 0 ? -i : i));
      return nums.indexOf(min) < 0 ? -min : min;
    };
    console.log(arr([-4, -2, 1, 4, 8]));
  </script>
</body>

</html>